/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.alxbrendmaquinarias.service;

import com.alxbrendmaquinarias.model.DetailInputDocument;
import com.alxbrendmaquinarias.model.InputDocument;
import com.alxbrendmaquinarias.repository.GenericDAO;
import java.util.List;
import java.util.Map;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 * @author Max
 */
@Service
public class InputDocumentServiceImpl implements InputDocumentService {

    @Autowired
    GenericDAO genericDAO;

    @Override
    public InputDocument save(InputDocument inputDocument) throws Exception {
        return genericDAO.create(inputDocument);
    }

    @Override
    public void update(InputDocument inputDocument) throws Exception {
        genericDAO.update(inputDocument);
    }

    @Override
    public void remove(InputDocument inputDocument) throws Exception {
        genericDAO.delete(inputDocument);
    }

    @Override
    public List list(String namedQuery) throws Exception {
        return genericDAO.findWithNamedQuery(namedQuery);
    }

    @Override
    public InputDocument getByIdLazyDetail(Integer id) throws Exception {
        InputDocument input = (InputDocument) genericDAO.getByIdLazy(InputDocument.class, id);
        List<DetailInputDocument> list = genericDAO.findWithQuery("SELECT d FROM DetailInputDocument d WHERE d.inputDocumentId.id="+id, null);
        input.setDetailInputDocumentList(list);
        return input;
    }

    @Override
    public Integer count(String query, Map<String, Object> param) throws Exception {
        return (Integer)genericDAO.countQuery(query, param);
    }
}
